package com.cqggrw.action;

import org.apache.struts2.ServletActionContext;

import com.cqggrw.domain.Flash;
import com.cqggrw.domain.Json;
import com.cqggrw.service.FlashserviceI;
import com.cqggrw.service.impl.FlashserviceImpl;
import com.opensymphony.xwork2.ModelDriven;

public class FlashAction extends BaseAction implements ModelDriven<Flash> {
	

	private static final long serialVersionUID = 1L;
	private FlashserviceI service = new FlashserviceImpl();
	public Flash flash = new Flash();
	private String realPath = ServletActionContext.getServletContext().getRealPath("");
	
	public String add() {
		if(service.add(flash, realPath)) {
			super.addAttributeForRequest("message", "添加成功！");
			return "success";
		}
		super.addAttributeForRequest("message", "添加失败！");
		return "faile";
	}
	
	public void getList() {
		super.writeJson(service.get(flash));
	}
	
	public void delete() {
		Json json = new Json();
		if (service.del(flash.getId())) {
			json.setSuccess(true);
			json.setMsg("删除成功!");
		} else {
			json.setSuccess(false);
			json.setMsg("删除失败!");
		}

		super.writeJson(json);
	}
	
	public String getById() {
		flash = service.getById(flash.getId());
		return "modify";
	}
	public String modify() {
		if(!service.modify(flash, realPath)) {
			super.addAttributeForRequest("message", "修改失败！");
			return "modify";
		}
		return "modifySuccess";
	}
	
	public Flash getModel() {
		return flash;
	}

}
